package com.zysd.collection.scheduler.controller;

import com.lensyn.common.utils.system.response.Response;
import com.zysd.collection.scheduler.condition.PageCondition;
import com.zysd.collection.scheduler.entity.SchedulerTaskTerminalMapping;
import com.zysd.collection.scheduler.service.model.ModelTerminalMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 任务模板与终端关联关系 Controller
 *
 * @author liuht
 * @date 2017/10/18 11:23
 */
@RestController
@RequestMapping("/scheduler")
public class ModelTerminalMappingController {

    @Autowired
    private ModelTerminalMappingService mappingService;

    /**
     * 根据任务模板主键 查询对应的终端关系列表
     *
     * @return Response
     */
    @RequestMapping(value = "/mappings/{taskModelId}/page", method = RequestMethod.GET)
    public Response mappings(@PathVariable Long taskModelId, PageCondition condition) {
//        if (!condition.checkPageParam()) {
//            return new Response().failure("分页查询条件不能为空");
//        }
        return new Response<>().success(mappingService.modelmMappings(taskModelId));
    }

    /**
     * 新增对应关系
     *
     * @return Response
     */
    @RequestMapping(value = "/mappings/add", method = RequestMethod.POST)
    public Response addMapping(@RequestBody List<SchedulerTaskTerminalMapping> mappings) {
        mappingService.addMapping(mappings);
        return new Response<>().success();
    }

    /**
     * 删除对应关系
     *
     * @return Response
     */
    @RequestMapping(value = "/mappings/delete", method = RequestMethod.POST)
    public Response deleteMapping(@RequestBody List<SchedulerTaskTerminalMapping> mappings) {
        mappingService.deleteMapping(mappings);
        return new Response<>().success();
    }
}
